package org.idea.qiyu.framework.threadpool.async.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @Author linhao
 * @Date created in 10:20 下午 2021/10/24
 */
@EnableAsync
@Configuration
public class AsyncCommonConfig {

    /**
     * 可以通过这里的bean统一配置，然后将其注入到各个带有@async注解的异步方法当中
     * @return
     */
    @Bean("asyncThreadPoolExecutor")
    public ThreadPoolTaskExecutor asyncThreadPoolExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setThreadNamePrefix("qiyu-threadPool-prefix");
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(10);
        executor.setKeepAliveSeconds(1000);
        executor.setAllowCoreThreadTimeOut(true);
        executor.initialize();
        return executor;
    }

}
